package com.acoffee.controller;

import com.acoffee.pojo.ClassRoom;
import com.acoffee.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author acoffee
 * @create 2021-11-18 11:59
 */
@Controller
@RequestMapping("/acoffee")
public class UserController {
    @RequestMapping("/StringView")
    public ModelAndView andView(@RequestParam(value = "name",required = false) String username, String password){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("username","传入用户名的是:"+username);
        modelAndView.addObject("password","传入密码的是:"+password);
        modelAndView.setViewName("stringView");
        return modelAndView;
    }

    @RequestMapping("/ListView")
    public ModelAndView andView1(@RequestParam List<Integer> ids){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("ids","传入参数的是:"+ids);
        modelAndView.setViewName("listView");
        return modelAndView;
    }

    @RequestMapping("/MapView")
    public ModelAndView andView2(@RequestParam Map map){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("map","传入的参数是："+map);
        modelAndView.setViewName("mapView");
        return modelAndView;
    }
    @RequestMapping("/ObjectView")
    public ModelAndView andView3(@Valid User user, BindingResult bindingResult){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user","传入的参数是："+user);
        modelAndView.addObject("bindingResult","传入的对象是："+bindingResult.toString());
        modelAndView.setViewName("objectView");
        return modelAndView;
    }

    @RequestMapping("/ManyObjectView")
    public ModelAndView andView4(ClassRoom classRoom){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("classRoom","传入的班级："+classRoom);
        modelAndView.setViewName("manyObjectView");
        return modelAndView;
    }
}
